package com.laguille.games.monopoly.commons.event;

import org.apache.commons.lang.Validate;

import com.laguille.games.monopoly.commons.player.Player;

/**
 * Event emitted when a player finishes his turn.
 *
 */
public class NextPlayerTurnEvent extends Event {

	private final Player oldPlayer;
	private final Player nextPlayer;
	
	public NextPlayerTurnEvent(Player nextPlayer, Player oldPlayer)  {
		Validate.notNull(nextPlayer);
		Validate.notNull(oldPlayer);
		this.nextPlayer = nextPlayer;
		this.oldPlayer = oldPlayer;
	}

	/**
	 * @return the oldPlayer
	 */
	public Player getOldPlayer() {
		return oldPlayer;
	}

	/**
	 * @return the nextPlayer
	 */
	public Player getNextPlayer() {
		return nextPlayer;
	}

	/* (non-Javadoc)
	 * @see java.lang.Object#hashCode()
	 */
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((nextPlayer == null) ? 0 : nextPlayer.hashCode());
		result = prime * result
				+ ((oldPlayer == null) ? 0 : oldPlayer.hashCode());
		return result;
	}

	/* (non-Javadoc)
	 * @see java.lang.Object#equals(java.lang.Object)
	 */
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		NextPlayerTurnEvent other = (NextPlayerTurnEvent) obj;
		if (nextPlayer == null) {
			if (other.nextPlayer != null)
				return false;
		} else if (!nextPlayer.equals(other.nextPlayer))
			return false;
		if (oldPlayer == null) {
			if (other.oldPlayer != null)
				return false;
		} else if (!oldPlayer.equals(other.oldPlayer))
			return false;
		return true;
	}

	/* (non-Javadoc)
	 * @see java.lang.Object#toString()
	 */
	@Override
	public String toString() {
		return "NextPlayerTurnEvent [oldPlayer=" + oldPlayer + ", nextPlayer="
				+ nextPlayer + "]";
	}
	

}
